//////////////////////////C++ prototypes //////////////////////////////////////////
//this are C++ prototypes implemented in other .cpp
#include "mytest.h"
//required openCV libs
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <ARDPDetector.h>
/////////////////////////C Wrappers //////////////////////////////////////////////////
//these are C wrappers

//global hashmap/handler to store images

//global vars

ARDPDetector detector;

    cv::Mat img = cv::imread("im1.png");

extern "C" char* ardp_initialize_image(char* fileName)
{
     cv::Mat image;
     image = cv::imread(fileName);
     if(!image.data)
     {
	std::cout << "Unable to load files!\n";
	return 0;
     }
     std::string windowName = "ARDrone testing";
     cv::namedWindow(windowName, CV_WINDOW_NORMAL);
     cv::imshow(windowName, image);
     cv::waitKey(0);
     //add to hashmap
      return fileName;
}

extern "C" int ardp_register_image(char* buf, char* name)
{
    //use hashmap to register image
}


extern "C" int ardp_template_matching(char* image, char* temp)
{
    //retrieve images from hashmap
    //my_templateMatch(image1, temp1, result, method);
    return 0; 
}

extern "C" int ardp_testfunc()
{
  return 152;
} 

extern "C" int ardp_initialize_detection(int mode, int sizex, int sizey, int temp_use, char* customTemp)
{
    cv::Mat temp; 
    int res=0;
    if(customTemp != NULL)
	res=detector.setTemplate(cv::imread(customTemp, CV_LOAD_IMAGE_GRAYSCALE));
    else 
	res=detector.setTemplate(temp_use);
    if(res!=0) return 1;
    
    detector.setMode(mode);
    detector.initialize(sizex, sizey);
    return 0;
}


extern "C" int ardp_detect(char* frame, int *x, int *y, int *width, int *heigth)
{
  return detector.detect(frame, *x, *y, *width, *heigth);
  //return 0;
}

extern "C" char* ardp_get_testimage()
{
    //std::cout << "Data: " << img.data << std::endl;
    return (char*)img.data;
}


extern "C" int ardp_display(char* frame)
{
  return detector.display(frame);
}


